<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  
    {include file="public/css"}
    {include file="public/js"}
</head>
<body>

<!-- 后台面包导航 -->
{:get_admin_breadcrumb()}

<blockquote class="layui-elem-quote" style="margin-top:10px;">说明：</blockquote>



<div class="layui-tab layui-tab-brief " lay-filter="docDemoTabBrief">
  <ul class="layui-tab-title">
    <li class="layui-this">邮件设置</li>
    <li >测试邮件</li>
  </ul>

  <div class="layui-tab-content" style="height: 100px;">
    <div class="layui-tab-item layui-show">

         <form class="layui-form" action="">
               <input type="hidden"  name="groupname" value="{$Request.action}">
               <div class="layui-form-item">
                <label class="layui-form-label">邮箱状态</label>
                <div class="layui-input-block">
                  <input type="radio" name="data[smtp_status]" value="1" {if $settings.email.smtp_status ==1}checked{/if} title="开启" checked="">
                  <input type="radio" name="data[smtp_status]" value="0" {if $settings.email.smtp_status ==0}checked{/if} title="关闭">
                </div>
              </div>              
 

              <div class="layui-form-item">
              <label class="layui-form-label">SMTP服务器</label>
              <div class="layui-input-inline">
                <input type="text" name="data[smtp_host]" lay-verify="smtp_host" placeholder="" autocomplete="off" class="layui-input" value="{$settings.email.smtp_host}">
              </div>
              <div class="layui-form-mid layui-word-aux">{:about('例如：smtp.qq.com')}</div>
            </div>
 
              <div class="layui-form-item">
              <label class="layui-form-label">SMTP端口 </label>
              <div class="layui-input-inline">
                <input type="text" name="data[smtp_port]" lay-verify="smtp_port" placeholder="" autocomplete="off" class="layui-input" value="{$settings.email.smtp_port}">
              </div>
              <div class="layui-form-mid layui-word-aux">{:about('默认 25')}</div>
            </div>
               <div class="layui-form-item">
              <label class="layui-form-label">SMTP用户名 </label>
              <div class="layui-input-inline">
                <input type="text" name="data[smtp_user]" lay-verify="smtp_user" placeholder="" autocomplete="off" class="layui-input" value="{$settings.email.smtp_user}">
              </div>
              <div class="layui-form-mid layui-word-aux">{:about('邮件服务器账号名称，一般是邮箱，格式 admin@qq.com')}</div>
            </div>   

              <div class="layui-form-item">
              <label class="layui-form-label">SMTP密码 </label>
              <div class="layui-input-inline">
                <input type="password" name="data[smtp_pass]" lay-verify="smtp_pass" placeholder="" autocomplete="off" class="layui-input" value="{$settings.email.smtp_pass}">
              </div>
              <div class="layui-form-mid layui-word-aux">{:about('邮件服务器账号密码')}</div>
            </div>



           <div class="layui-form-item">
            <label class="layui-form-label"></label>
              <div class="layui-input-block">
                  <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="form">确 定</button>
              </div>
            </div>

          </div>
</form>


     <div class="layui-tab-item">

               <div class="layui-form-item">
              <label class="layui-form-label">测试收件人 </label>
              <div class="layui-input-inline">
                <input type="text" name="data[test_email]" lay-verify="test_email" placeholder="测试邮箱" autocomplete="off" class="layui-input" id="test_email" value="">

              </div>
              <div class="layui-input-inline"> <button class="layui-btn layui-btn-danger" id="sendemail">发送测试邮件</button> 
                
              </div>
              <div class="layui-form-mid layui-word-aux"> {:about('邮件服务器账号名称，一般是邮箱，格式 admin@qq.com')}</div>
            </div>   
                
     </div>

</div> 



<script>
layui.use('form', function(){
  var form = layui.form;
  
  //监听提交
  form.on('submit(form)', function(data){
    // layer.msg(JSON.stringify(data.field));
    var data =data.field;
    $.post("{:url('settings/update')}",data,function(json){
       if(json.code == 0){
           layer.msg(json.msg);
       }else if(json.code == -1){
           layer.msg(json.msg);
       }
    });
    return false;
  });
});
</script>
<script>
$(function(){

  $("#sendemail").on("click",function(){
       $(this).addClass('layui-btn-disabled').attr('disabled','true').html('发送中...');
    var load = layer.load(2, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
     
   var test_email =  $("#test_email").val();
     $.post("{:url('email/test')}",{'test_email':test_email},function(json){
      layer.close(load); //关闭加载弹窗
      $("#sendemail").html('发送测试邮件').removeAttr('disabled').removeClass('layui-btn-disabled');
        if(json.code == 0){
           layer.msg(json.msg);
        }else{
           layer.msg(json.msg);
        }
     });

  });
});
</script>

</body>

</html>